var queryGridUrl = "../../report/findLoanInfosByCondition.action";
/**
 * 加载数据
 */
var loadData = function(){
	var headParam = [];
	headParam.push("loanId");
	headParam.push("borrowerName");
	headParam.push("credentialNo");
	headParam.push("pickupTime");
	headParam.push("marketer");
	headParam.push("marketerPost");
	headParam.push("operator");
	headParam.push("operatorPost");
	headParam.push("businessType");
	headParam.push("amount");
	headParam.push("term");
	headParam.push("guaranteeMethod");
	headParam.push("approvalTime");
	headParam.push("loanResult");
	headParam.push("apprBusinessType");
	headParam.push("apprAmount");
	headParam.push("apprTerm");
	headParam.push("apprRate");
	headParam.push("apprGuaranteeMethod2");
	headParam.push("repaymentMethod");
	headParam.push("examineHandler");
	headParam.push("isRenew");
	headParam.push("remark");

	var url = queryGridUrl;
	
	var defaultBtns = {"viewBtn":"hide","editBtn":"hide","removeBtn":"hide"};
	var operateBtns = [];
	
	var querParam = getQueryGridParam();
	if(querParam!=null)
	{
		var gridObj = {};
		gridObj["url"] = url;
		gridObj["headParam"] = headParam;
		gridObj["queryParam"] = querParam;
		gridObj["defaultBtns"] = defaultBtns;
		gridObj["operateBtns"] = operateBtns;
		gridObj["pk"] = "id";
		gridObj["page"] = true;
		gridObj["checked"]=false;
		gridObj["xuhao"]=true;
		
		var nTGridBean = new NTGridBean();
		nTGridBean.init(gridObj);
		nTGridBean.loadGrid();
	}
	
};

$(function(){
	$("#queryGridBtn").click(function(){ 
		loadData();
	});
});


/**
 * 获得查询列表参数
 */
var getQueryGridParam = function(){
	var processStat = $("#query_processStat").val()=="0"?"":$("#query_processStat").val();
	var businessType = $("#query_bussniessType").val()=="0"?"":$("#query_bussniessType").val();
	var startTime=$("#statisticStartTime").val();
	//var endTime=getFormatDateStr($("#statisticEndTime").val(),1);
	var endTime=$("#statisticEndTime").val();
	if(startTime==""){util.sysTips("开始时间必须选择","statisticStartTime"); return null;}
	else if(endTime==""){util.sysTips("结束时间必须选择","statisticEndTime"); return null;}
	else if(startTime!=""&&endTime!=""&&endTime<=startTime){util.sysTips("结束时间必须大于开始时间","statisticEndTime"); return null;}
	else{
		var param = {
				'processStat' : processStat,
				'businessType' : businessType,
				'queryStartTime' : startTime,
				'queryEndTime' : endTime
				
			};
			return param;
	}
	
};

$("#statisticStartTime").val(GetDateStr(-30));
$("#statisticEndTime").val(GetDateStr(0));
$("#statisticStartTime").datetimepicker({
	format: "yyyy-mm-dd",
	autoclose:true,
	startView: 2,
	minView: 2,
	language:'cn'
});
$("#statisticEndTime").datetimepicker({
	format: "yyyy-mm-dd",
	autoclose:true,
	startView: 2,
	minView: 2,
	language:'cn'
});

/*导出Excel和Pdf*/
var exportToExcel=function(){
	var startTime=$("#statisticStartTime").val();
	//var endTime=getFormatDateStr($("#statisticEndTime").val(),1);
	var endTime=$("#statisticEndTime").val();
	if(startTime==""){util.sysTips("开始时间必须选择","statisticStartTime"); return null;}
	else if(endTime==""){util.sysTips("结束时间必须选择","statisticEndTime"); return null;}
	else if(startTime!=""&&endTime!=""&&endTime<startTime){util.sysTips("结束时间必须大于开始时间","statisticEndTime"); return null;}
	else{
		var processStat = $("#query_processStat").val()=="0"?"":$("#query_processStat").val();
		var businessType = $("#query_bussniessType").val()=="0"?"":$("#query_bussniessType").val();
		//var buildingMsgCondition="";
		//var reportParams={};
		//reportParams["headerName"]="厂商编号#厂商名称#联系人#电话号码#手机号码#传真#电子邮箱#地址#注册时间#备注";
		//reportParams["title"]="厂商信息统计表";
		
			var params={};
			//params["reportBean.reportSqlNameCount"] = '';
			//params["reportBean.reportSqlNameGather"] = ''; 
			//params["reportBean.reportSqlName"] = '';
			//params["headerName"] ='厂商编号#厂商名称#联系人#电话号码#手机号码#传真#电子邮箱#地址#注册时间#备注';
			//params["title"] = "厂商信息统计表";
			params["processStat"]=processStat;
			params["businessType"]=businessType;
			params["queryStartTime"]=startTime;
			params["queryEndTime"]=endTime;
			//params["reportBean.reportParams.buildingMsgCondition"]=buildingMsgCondition;
		//	params["reportBean.reportParams.excelElementType"] = "0;0;0;0;0;0;0;";
			
			util.emmAjax({
				url : '../../report/loanReport.action',
				data:params,
				timeout:0,
				success : function(obj) {
					var excelData = util.str2Json(obj);
					var fileName = excelData.data;
					window.location.href="../../report/downloadExcel.action?fileName=" + fileName;
				}
			});
	}
	
}; 


/**
 *将json字符串转化为json对象
 */
function str2Json(jsonStr){
	var json = eval("(" + jsonStr + ")"); 
	return json;
};
